package com.fallsvc.chatroom.controller;

import com.fallsvc.chatroom.mapper.MessageMapper;
import com.fallsvc.chatroom.model.Message;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

/**
 * @auther falls_vc
 * description:
 * @date 2025/4/29  11:12
 */
@Slf4j
@RestController
public class MessageController {
    @Resource
    private MessageMapper messageMapper;
    @GetMapping("/message")
    public Object getMessage(int sessionId){
        // 1. 获得最新100条数据  时间降序
        List<Message> messages=messageMapper.getMessagesBySessionId(sessionId);
        // 2. 逆置   时间升序
        Collections.reverse(messages);
        //
        log.info("[getMessage] 获得信息成功 ：message:{}",messages);
        return  messages;
    }
}
